<template>
  <div class="function-config">
    <el-dialog
      :visible.sync="isShow"
      @close="triggerClose"
      :close-on-click-modal="false"
      @opened="triggerOpen"
      width="500"
    >
      <div style="height:580px;overflow-y:auto">
        <el-table
          class="p-table-list"
          border
          ref="multipleTable"
          :data="tables"
          tooltip-effect="dark"
          style="width: 100%"
          height="522"
          :show-overflow-tooltip="true"
          @selection-change="handleSelectionChange"
          :header-cell-style="{background:tableHeaderBGC}"
          @row-click="add"
        >
          <el-table-column type="index" :label="$t('cm.no')" align="center" width="60"></el-table-column>
          <el-table-column prop="projectCode" :label="$t('pur.project_code')" align="center"></el-table-column>
          <el-table-column prop="projectName" :label="$t('pur.project_name')" align="center"></el-table-column>
          <el-table-column prop="isValid" :label="$t('cm.is_valid')" align="center" :formatter="formatTableText"></el-table-column>
          <el-table-column prop="description" :label="$t('pur.project_description')" align="center"></el-table-column>
        </el-table>
        <div class="block pager-customer">
          <el-pagination
            background
            layout="total,prev,pager, next,jumper"
            :current-page.sync="pagingCurrentPageNum"
            :page-sizes="pagingPageSizes"
            :page-size="pagingPageSize"
            :total="pagingTotal"
            @size-change="pagingHandleSizeChange"
            @current-change="pagingHandleCurrentChange"
          >
          </el-pagination>
        </div>
      </div>
      <div slot="title" class="dialog-edit-head">
        <i>项目列表</i>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import * as Constant from '@/utils/constant'
import { mapState, mapActions, mapGetters } from 'vuex'
import Pagination from '@/mixins/Pagination'
import api_pur from '@/api/api_pur'
export default {
  /**
   *  项目列表
   */
  name: 'PurBasProjectList',
  props: {
    projectDislogVisible: {
      type: Boolean,
      default: false
    }
  },
  mixins: [Pagination],
  data () {
    return {
      isShow: this.projectDislogVisible,
      tables:[]
    }
  },
  created () {
    // this.getAllDataTable()
  },
  methods: {
    triggerOpen () { // 打开dislog
     this.getAllDataTable()
    },
    triggerClose () { // 关闭dislog
    },
    getAllDataTable () {
      this.queryTableList({
        pageNum: this.pagingCurrentPageNum,
        pageSize: this.pagingPageSize
      })
    },
    //统一与后台操作的方法
    queryTableList (params) {
      //这里的params是对象
      //注意 如果后台json转对象 时间类型好像会抛异常  转到后台 前台用 qs 来转换数据 设置一个全局拦截器 main.js 参考
      let _this = this
      let tables = []
      let totalCount = 0
      api_pur.purProjectLoadByPaging(params, result => {
        if (result.code === Constant.RT_SUCCESS) {
          //表格数据  数组            
          tables = result.data.results
          //分页数据
          totalCount = result.data.totalRows
        } else {
          // _this.$t('cm.tips')
          ALERT.error(result.data.msg)
        }
        _this.setPagingTotal(totalCount)
        this.tables = tables
      })
    },
    formatTableText (row, column, cellValue, index) {
      var fmtValue = null
      if (column.property === 'isValid') {
        fmtValue = this.isValidMap[row.isValid]
      }
      return fmtValue !== null && fmtValue !== undefined ? fmtValue : cellValue
    },
    add (row, column, event) {
      this.$emit('addProject', row)
    }
  },
  watch: {
    projectDislogVisible: {
      immediate: true,
      handler () {
        this.isShow = this.projectDislogVisible
      }
    },
    isShow () {
      if (!this.isShow) {
        this.$emit('closeProjectDislog')
      } else {
      }
    }
  },
  computed: {
    ...mapState({
      tableHeaderBGC: state => state.common.tableHeaderBGC
    }),
    ...mapGetters({
      isValidMap: 'dict/isValidMap'
    })
  }
}
</script>
<style lang="scss">
  .p-table-list {
   tbody tr:hover { cursor: pointer !important; }
  }
</style>
